
/*
 * FichaKine.java
 *
 * Created on 16-10-2012, 02:57:22 PM
 */
package SubsistemaPaciente.Fichas;

import clienteSandraParada.Login;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Jacqueline
 */
public class FichaPediatria extends javax.swing.JDialog {

    Long id;
    int fila;
    String profesional = Login.getUser().getRut();
    PanelPediatria p;

    /** Creates new form FichaKine */
    public FichaPediatria(java.awt.Frame parent, boolean modal, PanelPediatria p) {
        super(parent, modal);
        initComponents();
        this.p = p;
        setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel16 = new javax.swing.JPanel();
        botonAgregar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        jPanel17 = new javax.swing.JPanel();
        jLabel47 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        desarrolloSicomotor = new javax.swing.JTextArea();
        jScrollPane10 = new javax.swing.JScrollPane();
        vacunacionesPai = new javax.swing.JTextArea();
        jScrollPane11 = new javax.swing.JScrollPane();
        otrasVacunaciones = new javax.swing.JTextArea();
        jScrollPane12 = new javax.swing.JScrollPane();
        antecedentesFamiliares = new javax.swing.JTextArea();
        jScrollPane13 = new javax.swing.JScrollPane();
        patologiasCronicas = new javax.swing.JTextArea();
        jScrollPane14 = new javax.swing.JScrollPane();
        hospitalizaciones = new javax.swing.JTextArea();
        jScrollPane15 = new javax.swing.JScrollPane();
        anamnesis = new javax.swing.JTextArea();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jPanel18 = new javax.swing.JPanel();
        jLabel48 = new javax.swing.JLabel();
        jLabel49 = new javax.swing.JLabel();
        jLabel50 = new javax.swing.JLabel();
        jLabel51 = new javax.swing.JLabel();
        patologiaEmbarazo = new javax.swing.JTextField();
        jLabel52 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        controlado = new javax.swing.JComboBox();
        tipoParto = new javax.swing.JComboBox();
        pesoNacimiento = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        talla = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        eg = new javax.swing.JTextField();
        cc = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        nombreMadre = new javax.swing.JTextField();
        nombrePadre = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel53 = new javax.swing.JLabel();
        jLabel54 = new javax.swing.JLabel();
        jLabel55 = new javax.swing.JLabel();
        jLabel56 = new javax.swing.JLabel();
        jPanel19 = new javax.swing.JPanel();
        jLabel57 = new javax.swing.JLabel();
        jLabel58 = new javax.swing.JLabel();
        jLabel59 = new javax.swing.JLabel();
        nombres1 = new javax.swing.JTextField();
        apellidoPaterno = new javax.swing.JTextField();
        jLabel60 = new javax.swing.JLabel();
        rut = new componentes.Rut();
        apellidoMaterno = new javax.swing.JTextField();
        jLabel61 = new javax.swing.JLabel();
        fechaNacimiento = new javax.swing.JTextField();
        jLabel62 = new javax.swing.JLabel();
        telefono = new componentes.Telefono();
        jLabel63 = new javax.swing.JLabel();
        prevision = new javax.swing.JTextField();
        mensajeriaFormulario = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1099, 620));

        jPanel16.setMaximumSize(new java.awt.Dimension(1099, 596));
        jPanel16.setMinimumSize(new java.awt.Dimension(1099, 596));

        botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        botonAgregar.setText("Guardar");
        botonAgregar.setToolTipText("Guardar");
        botonAgregar.setAlignmentY(0.0F);
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.setToolTipText("Eliminar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        jPanel17.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos clínicos"));
        jPanel17.setMaximumSize(new java.awt.Dimension(550, 194));
        jPanel17.setMinimumSize(new java.awt.Dimension(550, 194));

        jLabel47.setText("Desarrollo sicomotor:");

        desarrolloSicomotor.setColumns(20);
        desarrolloSicomotor.setRows(5);
        jScrollPane2.setViewportView(desarrolloSicomotor);

        vacunacionesPai.setColumns(20);
        vacunacionesPai.setRows(5);
        jScrollPane10.setViewportView(vacunacionesPai);

        otrasVacunaciones.setColumns(20);
        otrasVacunaciones.setRows(5);
        jScrollPane11.setViewportView(otrasVacunaciones);

        antecedentesFamiliares.setColumns(20);
        antecedentesFamiliares.setRows(5);
        jScrollPane12.setViewportView(antecedentesFamiliares);

        patologiasCronicas.setColumns(20);
        patologiasCronicas.setRows(5);
        jScrollPane13.setViewportView(patologiasCronicas);

        hospitalizaciones.setColumns(20);
        hospitalizaciones.setRows(5);
        jScrollPane14.setViewportView(hospitalizaciones);

        anamnesis.setColumns(20);
        anamnesis.setRows(5);
        jScrollPane15.setViewportView(anamnesis);

        jLabel21.setText("Anamnesis inmediata:");

        jLabel22.setText("Hospitalizaciones:");

        jLabel23.setText("Patologias crónicas:");

        jLabel24.setText("Antecedentes familiares:");

        jLabel25.setText("Otras vacunaciones:");

        jLabel26.setText("Vacunaciones PAI:");

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel17Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel24)
                    .addComponent(jLabel22)
                    .addComponent(jLabel26)
                    .addComponent(jLabel25)
                    .addComponent(jLabel23)
                    .addComponent(jLabel47)
                    .addComponent(jLabel21))
                .addGap(10, 10, 10)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel47))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel26)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel25)
                    .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel24)
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel17Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel23))
                    .addGroup(jPanel17Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(14, 14, 14)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22)
                    .addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel18.setBorder(javax.swing.BorderFactory.createTitledBorder("Anamnesis remota"));
        jPanel18.setMaximumSize(new java.awt.Dimension(550, 745));
        jPanel18.setMinimumSize(new java.awt.Dimension(550, 745));

        jLabel48.setText("Patologías embarazo:");

        jLabel49.setText("Tipo de parto:");

        jLabel50.setText("Peso nacimiento:");

        jLabel51.setText("Controlado:");

        jLabel52.setText("EG:");

        controlado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        tipoParto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Parto Normal", "Cesaria" }));

        jLabel28.setText("Talla:");

        jLabel29.setText("CC:");

        jLabel30.setText("Nombre madre:");

        jLabel31.setText("Nombre padre:");

        jLabel32.setText("*");

        jLabel33.setText("*");

        jLabel34.setText("*");

        jLabel53.setText("*");

        jLabel54.setText("*");

        jLabel55.setText("*");

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel48)
                    .addComponent(jLabel51)
                    .addComponent(jLabel49)
                    .addComponent(jLabel50)
                    .addComponent(jLabel28)
                    .addComponent(jLabel52)
                    .addComponent(jLabel29)
                    .addComponent(jLabel30)
                    .addComponent(jLabel31))
                .addGap(37, 37, 37)
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addComponent(tipoParto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel54))
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addComponent(talla, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel55))
                    .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(eg, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cc, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel18Layout.createSequentialGroup()
                            .addComponent(pesoNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel53)))
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addComponent(patologiaEmbarazo, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel34))
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(nombreMadre, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nombrePadre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel33)
                            .addComponent(jLabel32))))
                .addGap(379, 379, 379)
                .addComponent(jLabel27)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel30)
                    .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(nombreMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel32)))
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addGap(443, 443, 443)
                        .addComponent(jLabel27))
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel31)
                            .addComponent(nombrePadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel33))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(patologiaEmbarazo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel48)
                            .addComponent(jLabel34))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(controlado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel51))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tipoParto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel49)
                            .addComponent(jLabel54))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pesoNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel50)
                            .addComponent(jLabel53))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(talla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel28)
                            .addComponent(jLabel55))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(eg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel52))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel29))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel56.setText("* Datos obligatorios");

        jPanel19.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos personales"));
        jPanel19.setMaximumSize(new java.awt.Dimension(550, 194));
        jPanel19.setMinimumSize(new java.awt.Dimension(550, 194));

        jLabel57.setText("Rut:");

        jLabel58.setText("Nombres :");

        jLabel59.setText("Apellido paterno:");

        nombres1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombres1ActionPerformed(evt);
            }
        });

        jLabel60.setText("Apellido materno:");

        jLabel61.setText("Fecha nacimiento:");

        jLabel62.setText("Teléfono:");

        jLabel63.setText("Previsión:");

        javax.swing.GroupLayout jPanel19Layout = new javax.swing.GroupLayout(jPanel19);
        jPanel19.setLayout(jPanel19Layout);
        jPanel19Layout.setHorizontalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addComponent(jLabel63)
                        .addGap(80, 80, 80)
                        .addComponent(prevision, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel61)
                            .addComponent(jLabel60)
                            .addComponent(jLabel59)
                            .addComponent(jLabel58)
                            .addComponent(jLabel57))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nombres1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rut, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel19Layout.createSequentialGroup()
                                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel19Layout.createSequentialGroup()
                                        .addComponent(fechaNacimiento, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel62))
                                    .addComponent(apellidoMaterno, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                                    .addComponent(apellidoPaterno, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(telefono, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(217, 217, 217))))
        );
        jPanel19Layout.setVerticalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(rut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel57))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombres1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel58))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel59)
                            .addComponent(apellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(apellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel60))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel62)
                            .addComponent(jLabel61))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(prevision, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel63))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        mensajeriaFormulario.setText("Área de mensajería");

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel16Layout.createSequentialGroup()
                                .addComponent(jLabel56)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 755, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel16Layout.createSequentialGroup()
                                .addGap(0, 345, Short.MAX_VALUE)
                                .addComponent(mensajeriaFormulario, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(164, 164, 164)))
                        .addComponent(botonAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCancelar)
                        .addGap(47, 47, 47))
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addComponent(jPanel18, javax.swing.GroupLayout.PREFERRED_SIZE, 506, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37))))
            .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel16Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(581, Short.MAX_VALUE)))
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGap(211, 211, 211)
                        .addComponent(jPanel18, 0, 304, Short.MAX_VALUE)))
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel56))
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botonAgregar)
                            .addComponent(botonCancelar)
                            .addComponent(mensajeriaFormulario))))
                .addContainerGap(44, Short.MAX_VALUE))
            .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel16Layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(387, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarActionPerformed
        //Boton formulacio agregar ficha clinica
        boolean control;
        boolean duplicada = false;
        if (this.getTitle().equals("Agregar Ficha Pediatria")) {
            duplicada = estaDuplicada(rut.getRut().getText(), Login.getUser().getRut());
            boolean datosObligatorios = llenoDatosObligatorios();
            if (duplicada == false && datosObligatorios == true) {
                if (controlado.getSelectedItem().equals("Si")) {
                    control = true;
                } else {
                    control = false;
                }
                Long idFicha = p.agregarFichaPediatraBD(rut.getRut().getText(), profesional, nombrePadre.getText(),
                        nombreMadre.getText(), patologiaEmbarazo.getText(), control, (String) tipoParto.getSelectedItem(),
                        pesoNacimiento.getText(), talla.getText(), eg.getText(), cc.getText(), desarrolloSicomotor.getText(),
                        vacunacionesPai.getText(), otrasVacunaciones.getText(), antecedentesFamiliares.getText(),
                        patologiasCronicas.getText(), hospitalizaciones.getText(), anamnesis.getText());
                service.FichaPediatra f = buscarFichaPediatra(idFicha);
                String valorNuevo = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Anamnesis inmediata: " + f.getAnamnesisInmediata() + "\n" + "Antecedentes familiares: " + f.getAntecedentesFamiliares() + "\n" + "CC: "
                        + f.getCc() + "\n" + "Desarrollo sicomotor: " + f.getDesarrolloSicomotor() + "\n" + "Eg: " + f.getEg() + "\n" + "Hospitalizaciones: " + f.getHospitalizaciones() + "\n" + "Nombre madre: " + f.getNombreMadre() + "\n" + "Nombre padre: " + f.getNombrePadre() + "\n" + "Otras vacunaciones: " + f.getOtrasVacunaciones() + "\n" + "Patología embarazo: " + f.getPatologiaEmbarazo()
                        + "\n" + "Patologías crónicas: " + f.getPatologiasCronicas() + "\n" + "Peso nacimiento: " + f.getPesoNacimiento() + "\n" + "Talla: " + f.getTalla() + "\n" + "Tipo parto: " + f.getTipoParto() + "\n" + "Vacunaciones Pai: " + f.getVacunacionesPai();
                registrar(Login.getUser(),"Ficha Pediatría", "Agregó ficha pediatría a profesional:" + f.getProfesional() + "de paciente :" + f.getPaciente(), "No aplica", valorNuevo);
                p.cargarFichas((java.util.List<service.FichaPediatra>) listarFichas());
            } else if (duplicada == true) {
                this.mensajeriaFormulario.setText("La ficha ya se encuentra en el sistema");
                this.mensajeriaFormulario.setForeground(Color.red);
            } else if (datosObligatorios == false) {
                this.mensajeriaFormulario.setText("Complete los campos obligatorios");
                this.mensajeriaFormulario.setForeground(Color.red);
            }
            if (duplicada == false && datosObligatorios == true) {
                this.dispose();
            }
        }
        if (this.getTitle().equals("Modificar Ficha Pediatria")) {
            if (controlado.getSelectedItem().equals("Si")) {
                control = true;
            } else {
                control = false;
            }
            service.FichaPediatra f = buscarFichaPediatra(id);
            String valorAnterior = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Anamnesis inmediata: " + f.getAnamnesisInmediata() + "\n" + "Antecedentes familiares: " + f.getAntecedentesFamiliares() + "\n" + "CC: "
                    + f.getCc() + "\n" + "Desarrollo sicomotor: " + f.getDesarrolloSicomotor() + "\n" + "Eg: " + f.getEg() + "\n" + "Hospitalizaciones: " + f.getHospitalizaciones() + "\n" + "Nombre madre: " + f.getNombreMadre() + "\n" + "Nombre padre: " + f.getNombrePadre() + "\n" + "Otras vacunaciones: " + f.getOtrasVacunaciones() + "\n" + "Patología embarazo: " + f.getPatologiaEmbarazo()
                    + "\n" + "Patologías crónicas: " + f.getPatologiasCronicas() + "\n" + "Peso nacimiento: " + f.getPesoNacimiento() + "\n" + "Talla: " + f.getTalla() + "\n" + "Tipo parto: " + f.getTipoParto() + "\n" + "Vacunaciones Pai: " + f.getVacunacionesPai();
            p.modificarFichaPediatriaBD(id, rut.getRut().getText(), profesional, nombrePadre.getText(),
                    nombreMadre.getText(), patologiaEmbarazo.getText(), control, (String) tipoParto.getSelectedItem(),
                    pesoNacimiento.getText(), talla.getText(), eg.getText(), cc.getText(), desarrolloSicomotor.getText(),
                    vacunacionesPai.getText(), otrasVacunaciones.getText(), antecedentesFamiliares.getText(),
                    patologiasCronicas.getText(), hospitalizaciones.getText(), anamnesis.getText());

            p.cargarFichas((java.util.List<service.FichaPediatra>) listarFichas());
            f = buscarFichaPediatra(id);
            String valorNuevo = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Anamnesis inmediata: " + f.getAnamnesisInmediata() + "\n" + "Antecedentes familiares: " + f.getAntecedentesFamiliares() + "\n" + "CC: "
                    + f.getCc() + "\n" + "Desarrollo sicomotor: " + f.getDesarrolloSicomotor() + "\n" + "Eg: " + f.getEg() + "\n" + "Hospitalizaciones: " + f.getHospitalizaciones() + "\n" + "Nombre madre: " + f.getNombreMadre() + "\n" + "Nombre padre: " + f.getNombrePadre() + "\n" + "Otras vacunaciones: " + f.getOtrasVacunaciones() + "\n" + "Patología embarazo: " + f.getPatologiaEmbarazo()
                    + "\n" + "Patologías crónicas: " + f.getPatologiasCronicas() + "\n" + "Peso nacimiento: " + f.getPesoNacimiento() + "\n" + "Talla: " + f.getTalla() + "\n" + "Tipo parto: " + f.getTipoParto() + "\n" + "Vacunaciones Pai: " + f.getVacunacionesPai();
            registrar(Login.getUser(),"Ficha Pediatría", "Modificó Ficha Pediatría a profesional:" + f.getProfesional() + "de paciente :" + f.getPaciente(), valorAnterior, valorNuevo);
            p.etiquetaMensajeria.setText("La Ficha se ha modificado exitosamente");
            this.dispose();

        } else if (this.getTitle().equals("Ver Ficha Pediatria")) {//Imprime la ficha Clinica
            //Imprime la ficha Clinica
            try {
                this.dispose();
                service.FichaPediatra fichak = this.buscarFichaPediatra(id);
                imprimirFichaClinica(fichak);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FichaPediatria.class.getName()).log(Level.SEVERE, null, ex);
            } catch (DocumentException ex) {
                Logger.getLogger(FichaPediatria.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_botonAgregarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_botonCancelarActionPerformed

    private void nombres1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombres1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nombres1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea anamnesis;
    private javax.swing.JTextArea antecedentesFamiliares;
    private javax.swing.JTextField apellidoMaterno;
    private javax.swing.JTextField apellidoPaterno;
    public javax.swing.JButton botonAgregar;
    public javax.swing.JButton botonCancelar;
    private javax.swing.JTextField cc;
    private javax.swing.JComboBox controlado;
    private javax.swing.JTextArea desarrolloSicomotor;
    private javax.swing.JTextField eg;
    private javax.swing.JTextField fechaNacimiento;
    private javax.swing.JTextArea hospitalizaciones;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel59;
    private javax.swing.JLabel jLabel60;
    private javax.swing.JLabel jLabel61;
    private javax.swing.JLabel jLabel62;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel mensajeriaFormulario;
    private javax.swing.JTextField nombreMadre;
    private javax.swing.JTextField nombrePadre;
    private javax.swing.JTextField nombres1;
    private javax.swing.JTextArea otrasVacunaciones;
    private javax.swing.JTextField patologiaEmbarazo;
    private javax.swing.JTextArea patologiasCronicas;
    private javax.swing.JTextField pesoNacimiento;
    private javax.swing.JTextField prevision;
    private componentes.Rut rut;
    private javax.swing.JTextField talla;
    private componentes.Telefono telefono;
    private javax.swing.JComboBox tipoParto;
    private javax.swing.JTextArea vacunacionesPai;
    // End of variables declaration//GEN-END:variables

    /**
     * Método que Setea el formulario de una Ficha Clínica
     **/
    public void limpiarFormulario() {
        //datos personales
        this.rut.getRut().setText("");
        this.nombres1.setText("");
        this.nombreMadre.setText("");
        this.nombrePadre.setText("");
        this.prevision.setText("");
        this.telefono.getTelefono().setText("");
        this.fechaNacimiento.setText("");
        //Datos Clinicos
        this.patologiaEmbarazo.setText("");
        this.controlado.setSelectedIndex(0);
        this.tipoParto.setSelectedIndex(0);
        this.pesoNacimiento.setText("");
        this.talla.setText("");
        this.eg.setText("");
        this.cc.setText("");
        this.desarrolloSicomotor.setText("");
        this.vacunacionesPai.setText("");
        this.otrasVacunaciones.setText("");
        ;
        this.antecedentesFamiliares.setText("");
        this.patologiasCronicas.setText("");
        this.hospitalizaciones.setText("");
        this.anamnesis.setText("");
    }

    public void llenarFormularioAgregar(service.Paciente pac) {
        //llenar datos paciente
        this.rut.getRut().setText(pac.getRut());
        this.nombres1.setText(pac.getNombres());
        this.apellidoPaterno.setText(pac.getApellidoPaterno());
        this.apellidoMaterno.setText(pac.getApellidoMaterno());
        this.prevision.setText(pac.getPrevision());
        this.telefono.getTelefono().setText(pac.getTelefono());
        this.fechaNacimiento.setText(pac.getFechaNac());
        //bloquear los campos
        this.rut.getRut().setEditable(false);
        this.nombres1.setEditable(false);
        this.apellidoPaterno.setEditable(false);
        this.apellidoMaterno.setEditable(false);
        this.prevision.setEditable(false);
        this.telefono.getTelefono().setEditable(false);
        this.telefono.getTelefono().setEditable(false);
        this.fechaNacimiento.setEditable(false);
    }

    public void llenarFormularioModificar(service.FichaPediatra fi) {
        service.Paciente pac = buscarPaciente(fi.getPaciente());
        llenarFormularioAgregar(pac);
        //llenar datos clinicos de la ficha
        this.nombreMadre.setText(fi.getNombreMadre());
        this.nombrePadre.setText(fi.getNombrePadre());
        this.patologiaEmbarazo.setText(fi.getPatologiaEmbarazo());
        if (fi.isActivo() == true) {
            this.controlado.setSelectedItem("Si");
        } else {
            this.controlado.setSelectedItem("No");
        }
        if (fi.getTipoParto().equals("Parto Normal")) {
            this.tipoParto.setSelectedItem("Parto Normal");
        } else {
            this.tipoParto.setSelectedItem("Cesarea");
        }
        this.pesoNacimiento.setText(fi.getPesoNacimiento());
        this.talla.setText(fi.getTalla());
        this.eg.setText(fi.getEg());
        this.cc.setText(fi.getCc());
        this.desarrolloSicomotor.setText(fi.getDesarrolloSicomotor());
        this.vacunacionesPai.setText(fi.getVacunacionesPai());
        this.otrasVacunaciones.setText(fi.getOtrasVacunaciones());
        this.antecedentesFamiliares.setText(fi.getAntecedentesFamiliares());
        this.patologiasCronicas.setText(fi.getPatologiasCronicas());
        this.hospitalizaciones.setText(fi.getHospitalizaciones());
        this.anamnesis.setText(fi.getAnamnesisInmediata());
    }

    public service.Paciente buscarPaciente(String paciente) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();

        java.util.List<service.Paciente> pacientes = port.listarPacientes();
        //buscar paciente por el rut
        for (int i = 0; i < pacientes.size(); i++) {
            if (pacientes.get(i).getRut().equals(paciente)) {
                return pacientes.get(i);
            }
        }
        return null;
    }

    public void habilitarCamposFormulario(boolean habilitar) {
        this.nombreMadre.setEditable(habilitar);
        this.nombrePadre.setEditable(habilitar);
        this.patologiaEmbarazo.setEditable(habilitar);
        this.controlado.setEnabled(habilitar);
        this.tipoParto.setEnabled(habilitar);
        this.pesoNacimiento.setEditable(habilitar);
        this.talla.setEditable(habilitar);
        this.eg.setEditable(habilitar);
        this.cc.setEditable(habilitar);
        this.desarrolloSicomotor.setEnabled(habilitar);
        this.vacunacionesPai.setEnabled(habilitar);
        this.otrasVacunaciones.setEnabled(habilitar);
        this.antecedentesFamiliares.setEnabled(habilitar);
        this.patologiasCronicas.setEnabled(habilitar);
        this.hospitalizaciones.setEnabled(habilitar);
        this.anamnesis.setEnabled(habilitar);
    }

    public void configurarBotones(String formulario) {
        if (formulario.equals("agregar")) {
            this.botonAgregar.setText("Aceptar");
            this.botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
        } else if (formulario.equals("modificar")) {
            this.botonAgregar.setText("Guardar");
            this.botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
        } else {
            this.botonAgregar.setText("Exportar");
            this.botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/pdf.png")));
        }

    }

    private boolean estaDuplicada(String paciente, String profesional) {
        java.util.List<service.FichaPediatra> fichas = listarFichas();

        for (int i = 0; i < fichas.size(); i++) {
            if (fichas.get(i).getPaciente().equals(paciente) && fichas.get(i).getProfesional().equals(profesional)) {
                return true;
            }
        }
        return false;
    }

    private static java.util.List<service.FichaPediatra> listarFichas() {
        service.FichaPediatraWSService service = new service.FichaPediatraWSService();
        service.FichaPediatraWS port = service.getFichaPediatraWSPort();
        return port.listarFichasPediatra();
    }

    public service.FichaPediatra buscarFichaPediatra(Long ficha) {
        service.FichaPediatraWSService service = new service.FichaPediatraWSService();
        service.FichaPediatraWS port = service.getFichaPediatraWSPort();

        java.util.List<service.FichaPediatra> fichasPedi = port.listarFichasPediatra();
        //buscar paciente por el rut
        for (int i = 0; i < fichasPedi.size(); i++) {
            if (fichasPedi.get(i).getId().equals(ficha)) {
                return fichasPedi.get(i);
            }
        }
        return null;
    }

    public String eligeDireccionArchivo() {
        String dirArchivo = "";
        JFileChooser jFileChooser1 = new JFileChooser();
        jFileChooser1.setDialogTitle("Guardar archivo:");
        jFileChooser1.setVisible(true);

        int r = jFileChooser1.showSaveDialog(null);
        if (r == JFileChooser.APPROVE_OPTION) {
            File file = jFileChooser1.getSelectedFile();
            dirArchivo = String.valueOf(file);
        }
        dirArchivo = dirArchivo.replace('\\', '/') + ".pdf";
        return dirArchivo;

    }

    private void imprimirFichaClinica(service.FichaPediatra ficha) throws FileNotFoundException, DocumentException {
        service.Paciente paciente = buscarPaciente(ficha.getPaciente());
        Document documento = new Document();
        String dirArchivo = eligeDireccionArchivo();

        FileOutputStream ficheroPdf = new FileOutputStream(dirArchivo);// Se crea el OutputStream para el fichero donde queremos dejar el pdf.
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        documento.open();// Se abre el documento.

        Paragraph titulo = new Paragraph("FICHA CLINICA PEDIATRIA");
        titulo.setAlignment(Element.ALIGN_CENTER);
        titulo.setSpacingAfter(20);
        documento.add(titulo);

        Paragraph datosPersonales = new Paragraph("Datos Personales");
        datosPersonales.setAlignment(Element.ALIGN_LEFT);
        datosPersonales.setSpacingAfter(20);
        documento.add(datosPersonales);

        PdfPTable table = new PdfPTable(2);
        table.addCell("Rut: ");
        table.addCell(paciente.getRut());
        table.addCell("Nombres: ");
        table.addCell(paciente.getNombres());
        table.addCell("Apellido Paterno:");
        table.addCell(paciente.getApellidoPaterno());
        table.addCell("Apellido Materno: ");
        table.addCell(paciente.getApellidoMaterno());
        table.addCell("Previsión: ");
        table.addCell(paciente.getPrevision());
        table.addCell("Fecha de Nacimiento: ");
        table.addCell(paciente.getFechaNac());
        table.addCell("Telefono: ");
        table.addCell(paciente.getTelefono());
        documento.add(table);

        Paragraph datosClinicos = new Paragraph("Datos Clínicos");
        datosClinicos.setAlignment(Element.ALIGN_LEFT);
        datosClinicos.setSpacingAfter(20);
        documento.add(datosClinicos);

        PdfPTable tabla = new PdfPTable(2);
        tabla.addCell("Nombre Madre: ");
        tabla.addCell(ficha.getNombreMadre());
        tabla.addCell("Nombre Padre: ");
        tabla.addCell(ficha.getNombrePadre());
        tabla.addCell("Patologías Embarazo");
        tabla.addCell(ficha.getPatologiaEmbarazo());
        tabla.addCell("Controlado: ");
        if (ficha.isControlado() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Tipo de Parto: ");
        tabla.addCell(ficha.getTipoParto());
        tabla.addCell("Peso Nacimiento");
        tabla.addCell(ficha.getPesoNacimiento());
        tabla.addCell("Talla: ");
        tabla.addCell(ficha.getTalla());
        tabla.addCell("EG");
        tabla.addCell(ficha.getEg());
        tabla.addCell("CC");
        tabla.addCell(ficha.getCc());
        tabla.addCell("Desarrollo Sicomotor: ");
        tabla.addCell(ficha.getDesarrolloSicomotor());
        tabla.addCell("Vacunaciones PAI: ");
        tabla.addCell(ficha.getVacunacionesPai());
        tabla.addCell("Otras Vacunaciones: ");
        tabla.addCell(ficha.getOtrasVacunaciones());
        tabla.addCell("Antecedentes Familiares: ");
        tabla.addCell(ficha.getAntecedentesFamiliares());
        tabla.addCell("Patologías Crónicas");
        tabla.addCell(ficha.getPatologiasCronicas());
        tabla.addCell("Hospitalizaciones: ");
        tabla.addCell(ficha.getHospitalizaciones());
        tabla.addCell("Anamnesis Inmediata: ");
        tabla.addCell(ficha.getAnamnesisInmediata());
        documento.add(tabla);

        documento.close();
        abrirArchivo(dirArchivo);
    }

    public void abrirArchivo(String direccion) {
        //Abre el documento pdf
        try {
            File file = new File(direccion);
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private boolean llenoDatosObligatorios() {
        if (this.nombreMadre.getText().equals("") || this.nombrePadre.getText().equals("") || this.patologiaEmbarazo.getText().equals("")
                || this.tipoParto.getSelectedItem() == null || this.pesoNacimiento.getText().equals("") || this.talla.getText().equals("")) {
            return false;
        }
        return true;
    }

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }
    
     public void ocultarAsteriscosFormulario(boolean ocultar){
        if(ocultar==true){
            this.jLabel32.setText("");
            this.jLabel33.setText("");
            this.jLabel34.setText("");
            this.jLabel53.setText("");
            this.jLabel54.setText("");
            this.jLabel55.setText("");
            this.jLabel56.setText("");
            this.mensajeriaFormulario.setText("");
        }else{
            this.jLabel32.setText("*");
            this.jLabel33.setText("*");
            this.jLabel34.setText("*");
            this.jLabel53.setText("*");
            this.jLabel54.setText("*");
            this.jLabel55.setText("*");
            this.jLabel56.setText("*Datos obligatorios");
            this.mensajeriaFormulario.setText("Área de mensajería");
        }
    }

}
